home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Genie / Projects / Pedestal / Source / Sources / Streams / PedDispenserString.cc < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-24  |  1.9 KB  |  85 lines

  1. /*    =====================
  2.  *    PedDispenserString.cc
  3.  *    =====================
  4.  */
  5.  
  6. #include "SiesString.hh"
  7.  
  8. #include "PedDispenserString.hh"
  9. #include "PedBuffer.hh"
  10. #include "PedStreamInputBuffered.hh"
  11.  
  12. PedDispenserString::PedDispenserString(PedStreamInputBuffered &inStream)
  13. : mStream(inStream)
  14. {
  15.     mStream.retain();
  16.     mStream.Flush();
  17. }
  18.  
  19. PedDispenserString::~PedDispenserString()
  20. {
  21.     mStream.release();
  22. }
  23.  
  24.  
  25. bool
  26. PedDispenserString::GetString(SiesString &outString)
  27. {
  28.     outString.Set("\p");
  29.     long count = mStream.CountAheadThroughChar('\n');
  30.     if (count >= 0) {
  31.         while (count == 0) {
  32.             long size = mStream.SizeOfNextChunk();
  33.             PedBuffer buf(size);
  34.             buf.SetLength(mStream.GetChunk(size, buf.Ptr()));
  35.             outString.Append(buf.Ptr(), buf.Length());
  36.             count = mStream.CountAheadThroughChar('\n');
  37.         }
  38.         if (count > 0) {
  39.             PedBuffer buf(count);
  40.             buf.SetLength(mStream.GetChunk(count, buf.Ptr()) - 1);
  41.             outString.Append(buf.Ptr(), buf.Length());
  42.             count = mStream.CountAheadThroughChar('\n');
  43.         } else {
  44.             // trailing newline is missing
  45.         }
  46.     } else {
  47.         return false;
  48.     }
  49.     return true;
  50. }
  51.  
  52. #if 0
  53. bool
  54. PedDispenserString::GetString(SiesString &outString)
  55. {
  56.     outString.Set("\p");
  57.     long countCR, countLF, count, min, max;
  58.     countCR = mStream.CountAheadThroughChar(13);
  59.     countLF = mStream.CountAheadThroughChar(10);
  60.     min = (countCR < countLF) ? countCR : countLF;
  61.     max = (countCR > countLF) ? countCR : countLF;
  62.     count = (min == 0) ? max : min;
  63.     if (count >= 0) {
  64.         while (count == 0) {
  65.             long size = mStream.SizeOfNextChunk();
  66.             PedBuffer buf(size);
  67.             buf.SetLength(mStream.GetChunk(size, buf.Ptr()));
  68.             outString.Append(buf.Ptr(), buf.Length());
  69.             count = mStream.CountAheadThroughChar(13);
  70.         }
  71.         if (count > 0) {
  72.             PedBuffer buf(count);
  73.             buf.SetLength(mStream.GetChunk(count, buf.Ptr()) - 1);
  74.             outString.Append(buf.Ptr(), buf.Length());
  75.             count = mStream.CountAheadThroughChar(13);
  76.         } else {
  77.             // trailing newline is missing
  78.         }
  79.     } else {
  80.         return false;
  81.     }
  82.     return true;
  83. }
  84. #endif
  85.